package com.smartlifev30.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

/**
 * @author tys
 * @date 2018/8/29
 */

public class NetUtils {


    /**
     * {@link NetworkInfo#getType()}
     *
     * @param context
     * @return
     */
    public static int getCurrentNetStatus(Context context) {
        ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
        if (cm != null) {
            NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo();
            if (activeNetworkInfo != null && activeNetworkInfo.isConnected()) {
                return activeNetworkInfo.getType();
            }
        }
        return -1;
    }


}
